package com.bootssm.controller;

import com.bootssm.enity.Result;
import com.bootssm.enity.TeamBall;
import com.bootssm.enity.TeamBallQueryV0;
import com.bootssm.service.TeamBallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teamball")
public class TeamBallController {
    @Autowired
    TeamBallService teamBallService;

    @PostMapping("/findAll")
    public List<TeamBall> findAll(@RequestBody TeamBallQueryV0 teamBallQueryV0) {
        List<TeamBall> teamBallList = teamBallService.findAll(teamBallQueryV0);
        return teamBallList;

    }


    @GetMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id") String teamballid) {
        try {
            teamBallService.deleteById(teamballid);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result("500", "delete wrong!");
        }
        return new Result("200", "delete!");
    }

    @GetMapping("/findById/{id}")
    public TeamBall findById(@PathVariable("id") String teamballId) {
        TeamBall teamBall = teamBallService.findById(teamballId);
        return teamBall;
    }

    @PostMapping("/save")
    public Result save(@RequestBody TeamBall teamBall){
        try {
            teamBallService.save(teamBall);
        }catch (Exception e){
            e.printStackTrace();
            return new Result("500","save wrong!");
        }
        return new Result("200","save!");
    }

@PostMapping("/update")
    public Result update(@RequestBody TeamBall teamBall){
        try {
            teamBallService.update(teamBall);
        }catch (Exception e){
            e.printStackTrace();
            return new Result("500","update wrong!");
        }
    return new Result("200","update!");
}
}
